package main

import (
	"fmt"
	"log"
	"os"
)

var (
	WarningLogger *log.Logger
	InfoLogger    *log.Logger
	ErrorLogger   *log.Logger
)

func init() {
	file, err := os.OpenFile("test.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0660)
	if err != nil {
		log.Fatal(err)
	}
	InfoLogger = log.New(file, "[INFO]", log.Ldate|log.Ltime|log.Lshortfile)
	WarningLogger = log.New(file, "[WARN]", log.LstdFlags|log.Lshortfile)
	ErrorLogger = log.New(file, "[ERROR]", log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile)
}

func logPrinta(baseStr string) {
	for i := 0; i < 10; i++ {
		msg := fmt.Sprintf("%s_%d", baseStr, i)
		log.Println(msg)
	}
}

func main() {

	InfoLogger.Println("[常见写法]启动服务....")
	InfoLogger.Println("[日期简写]正常上报....")
	WarningLogger.Println("[文件长路径]不严重的错误...")
	ErrorLogger.Println("[微秒时间戳]严重error...")
}
